
// 类的实现
var Person = function(name, yearOfBirth, job) {
  this.name = name; // 属性的添加
  this.yearOfBirth = yearOfBirth;
  this.job = job;
}

//添加方法：
Person.prototype.calculateAge = function() {
  var age = new Date().getFullYear() - this.yearOfBirth;
  return age;
}

var john = new Person('John', 1999, 'teacher');
console.log(john.calculateAge()); // 调用方法


// 继承的实现
var Athlete = function(name, yearOfBirth, job, olympicGames, medals) {
  Person.call(this, name, yearOfBirth, job); // 通过call将this绑在Person5上
  this.olympicGames = olympicGames;
  this.medals = medals;
}

// 手动设置原型链
Athlete.prototype = Object.create(Person.prototype); // 先设置
Athlete.prototype.wonMedal = function () { //再加自己的方法
    this.medals++;
    console.log(this.medals);
  }
var johnAthlete = new Athlete('John', 1990,  'swimmer', 3, 10);
console.log(johnAthlete.calculateAge());// 继承原型链上的方法
johnAthlete.wonMedal();// 自己的方法


